package com.aaa.book_mall.controller;

import com.aaa.book_mall.dao.RejectDao;
import com.aaa.book_mall.dao.RequestDao;
import com.aaa.book_mall.dao.impl.RejectDaoImpl;
import com.aaa.book_mall.dao.impl.RequestDaoImpl;
import com.aaa.book_mall.entity.Reject;
import com.aaa.book_mall.entity.Request;
import com.aaa.book_mall.util.LayTab;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * fileName:RejectController
 * description:
 * author:付亚星
 * createTime:2021/1/30 19:45
 * version:1.0.0
 */
@RestController
@RequestMapping("/reject")
public class RejectController {

    private RejectDao rejectDao = new RejectDaoImpl();
    private RequestDao requestDao = new RequestDaoImpl();

    /**
     * 查询所有驳回信息
     */
    @RequestMapping("/getAllReject")
    public LayTab getAllReject(Reject reject){
        System.out.println(reject);
        //        查询出来目标数据
        List<Map<String, Object>> allOutInfo = rejectDao.getAllReject(reject);
//        查询出来所有的总条数
        int count = rejectDao.queryNoCountAll();
        LayTab layTab = new LayTab(count, allOutInfo);
        return layTab;
    }

    /**
     * 再次申请,修改驳回订单状态
     */
    @RequestMapping("/updateStatus")
    public Map updateStatus(@RequestBody Reject reject){
        System.out.println("进入驳回状态修改");
        //修改状态为待审核
        String status = "0";
        //        1、更改t_out表中的状态
        int statusV = rejectDao.updateStatus(reject.getAudit_number(),status);
        System.out.println("修改驳回表状态："+statusV);
        int statusV1 = requestDao.updateStatus(reject.getAudit_number(),status);
        System.out.println("修改申请表状态："+statusV1);

        HashMap<Object, Object> map = new HashMap<>();
        int i =1;
        if(i>0){
            map.put("code","1");
            map.put("msg","操作成功");
        }else{
            map.put("code","0");
            map.put("msg","操作失败");
        }
        return map;
    }

    @RequestMapping("/showInfoReject")
    public LayTab showInfoReject(String audit_number){
        System.out.println("驳回订单"+audit_number);
//        查询对应的详情表
        List<Map<String, Object>> maps = rejectDao.showInfoReject(audit_number);
        System.out.println(maps);
        LayTab layTab = new LayTab(maps.size(), maps);
        return layTab;
    }
}
